import request from 'umi-request';
import type {
  Problem,
  ProblemPostVO,
  ResultVOProblem,
  ResultVOListProblem,
  ResultVOObject,
  ResultVOBoolean,
} from 'src/types/openapi';

export async function getAllProblem() {
  return request<ResultVOListProblem>('/api/problems');
}

export async function getProblemById(id: number) {
  return request<ResultVOProblem>(`/api/problems/${id}`);
}

export async function addProblem(data: ProblemPostVO) {
  return request<ResultVOObject>('/api/problems', {
    method: 'POST',
    data,
  });
}

export async function updateProblem(problem: Problem) {
  return request<ResultVOProblem>('/api/problems', {
    method: 'PUT',
    params: { problem },
  });
}

export async function deleteProblem(id: number) {
  return request<ResultVOBoolean>(`/api/problems/${id}`, {
    method: 'DELETE',
  });
}
